﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using Facebook.Schema;
using PivotCollectionTools.Xml;

namespace TestApplicationObjects
{
    class Program
    {
        static void Main(string[] args)
        {
            ApiMethod();
            return;

        }

        static void friends_ActionChanged(object sender, EventArgs e)
        {
            Console.WriteLine(sender.ToString());
        }

        public static void ApiMethod()
        {
            TextReader tr = new StreamReader("../../../FacebookFriends.xml");
            XmlSerializer s = new XmlSerializer(typeof(List<user>));
            var data = s.Deserialize(tr) as List<user>;

            var friends = new PivotXml() { Name = "Facebook Friends", SchemaVersion = 1.0m };

            friends.AddCategory(new FacetCategory("Activities", FacetDataType.String, true, true, true));
            friends.AddCategory(new FacetCategory("Books", FacetDataType.String, true, true, true));
            friends.AddCategory(new FacetCategory("Interests", FacetDataType.String, true, true, true));

            friends.AddItemList("image\\imag.xml");
            int counter = 0;
            foreach (user friend in data)
            {
                var newItem = new Item(counter.ToString()) { Name = friend.name };

                newItem.Facets.AddTextFacet("Activities", friend.activities.AsListOfValues());
                newItem.Facets.AddTextFacet("Books", friend.books.AsListOfValues());

                friends.ItemList[0].Items.Add(newItem);
                counter++;
            }
            friends.WriteXml("../../../TestObject.cxml");
        }
    }
}
